package com.t2t.top.framework.rocketmq.utils;

import com.taobao.diamond.manager.ManagerListenerAdapter;
import com.taobao.diamond.manager.impl.DefaultDiamondManager;

public class DiamondUtil {

	private static final int TIME_OUT = 5000;

	public static DefaultDiamondManager registDiamondListener(ManagerListenerAdapter diamondListener, String group,String dataId) {
		DefaultDiamondManager manager = new DefaultDiamondManager(group, dataId, diamondListener);
		// 让启动的时候也收到配置信息
		diamondListener.receiveConfigInfo(manager.getAvailableConfigureInfomation(TIME_OUT));
		return manager;
	}

	public static void main(String[] args) {
		// 替换代码中的ConfigCenter.diamondIpList成ip,然后可执行main
		ManagerListenerAdapter diamondListener = new ManagerListenerAdapter() {
			@Override
			public void receiveConfigInfo(String configInfo) {
				System.out.println("restart service : " + configInfo);
			}
		};
		DiamondUtil.registDiamondListener(diamondListener, "rocketmq", "url");
	}

}
